<?php
/**
 * 过滤器链
 *
 * @version $Id$
 * @package if
 * @subpackage util.filter
 * @since 1.0
 */
class IFilterChain extends IObject {
	private $filters = array();
	private $object;
	
	/**
	 * 构造器
	 *
	 * @param mixed &$object 需要过滤的对象
	 * @since 1.0
	 */
	function __construct(&$object) {
		$this->object = &$object;
	}
	
	/**
	 * 添加过滤器
	 *
	 * @param IFilter $filter 过滤器
	 * @since 1.0
	 */
	function addFilter(IFilter $filter) {
		$this->filters[] = $filter;
	}
	
	/**
	 * 执行当前的过滤器
	 *
	 * @since 1.0
	 * @see doNext
	 */
	function doFilter() {
		$this->doNext();
	}
	
	/**
	 * 执行链条中下一个过滤器
	 *
	 * @since 1.0
	 */
	function doNext() {
		$filter = current($this->filters);
		next($this->filters);
		if ($filter) {
			$filter->doFilter($this->object, $this);
		}
	}
	
	/**
	 * 取得filter列表
	 *
	 * @return array
	 * @since 1.0
	 */
	function filters() {
		return $this->filters;
	}
}

?>